
unsigned __random_seed = 1;

int atoi(const char *str)
{
	int value = 0;

	while(*str>='0'&&*str<='9')
	{
		value *= 10;
		value += *str-'0';
		str++;
	}

	return value;
}

/* it is mandatory to initialize the random seed with a value */
void srand(unsigned seed)
{
	__random_seed= seed;
	return;
}

/*
 * This algorithm is mentioned in the ISO C standard, here extended for 32 bits.
 */
int rand()
{
    unsigned int next = __random_seed;
    int result;

    next *= 1103515245;
    next += 12345;
    result = (unsigned int) (next / 65536) % 2048;

    next *= 1103515245;
    next += 12345;
    result <<= 10;
    result ^= (unsigned int) (next / 65536) % 1024;

    next *= 1103515245;
    next += 12345;
    result <<= 10;
    result ^= (unsigned int) (next / 65536) % 1024;

    __random_seed = next;

    return result;
}
